home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1996 #15
/
Monster Media Number 15 (Monster Media)(July 1996).ISO
/
os2
/
pmcstex.zip
/
PM4EPM.E
< prev
next >
Wrap
Text File
|
1996-05-17
|
17KB
|
484 lines
/*
pm4epm.e
PM for EPM. pm_command family: command with expansion dependend
on the currently edited file
c Petr Mikulík - Brno - Czech Republic - 20.2.1996
mikulik@physics.muni.cz, http://www.sci.muni.cz/~mikulik/
Update for emtex options: 17.5.1996
Update for dvips options: 15.5.1996
*/
/*
USAGE: I use this macro file for actions on the EPM toolbar, and in the package
CSTeX that implements menu for many (La)TeX related commands.
INSTALLATION:
1. cite this file (pm4epm) in the actions.lst file
2. write include pm4epm into your Profile.erx
3. You should have already installed EPMTeX and WETEX by Wagner
COMMANDS DEFINED HERE:
pm_expand - expands the string and then executes it
pm_command_os2 - expands the string and runs it as os2 program
pm_command_os2fs - expands the string and runs full-screen os2 program
pm_command_cmd - expands the string and runs it through cmd
pm_command_pm - expands the string and runs it (only START)
pm_command_dos - expands the string and runs it as dos program
pm_command_dosfs - expands the string and runs full-screen dos program
etc.
The expansion depends on the edited file (currently active file in the editor).
SYNTAX of pm_expand WITH EXAMPLE: work file is e:\tmp\a.tex =>
Syntax Internal Variable Explanation Example
%w EFname work file name a
%.w EFext work file extension tex
%W EFwholename full name without extension e:\tmp\a
%.W EF full name e:\tmp\a.tex
The same holds for the Master file specified by the MASTER: key (see below):
%m %.m %M %.M
Both types written in the Unix format (i.e. backslahes replaced by slashes):
%x %.x %X %.X for the work file e.g. %.X = e:/tmp/a.tex
%n %.n %N %.N for the master file
%h MFdrive drive of the master file (e:)
%d MainDirectory directory of the master file (\tmp)
%D XMainDirectory directory in the Unix format (/home/petr/tex)
Key specifications:
The work file can have some of the following keyword written on its first line.
They are expanded as well according to this rules:
Syntax Internal Variable Introducing key word If key not specified
%master MF Master: MF := EF
%format TheFormat Format: envir. var. TEXFORMATDEFAULT
of "latex"
%etc TheEtc Etc: empty string
%orient TheOrient Orientation: empty string
%choice TheChoice Choice: empty string
The following are expanded as verbatims, e.i. from the first char occuring after
the key to the next same char:
%opts Opts: empty string
%viewopts ViewOpts: empty string
%optsdvips dvips: empty string
%optsemtex EmtexOpt: empty string
The syntax $(Name) expands environmental variable Name
*** Example 1 ***
We edit file E:\TEXT\FERDA.TEX having the first line
% Master: SEKORA.TEX Format: latex209 Choice: none
Then commands are expanded:
"copy %.W %W.old" => "copy E:\TEXT\FERDA.TEX E:\TEXT\FERDA.old"
"type %w%.w" => "type FERDA.TEX"
"%format.cmd %.N" => "latex209.cmd E:/TEXT/SEKORA.TEX"
"echo %choice *%etc*" => "echo none **"
*** Example 2 ***
We edit file E:\TEXT\BROUK.TEX having the first line
% ViewOpts: +/tr1 /m1440+ Etc: does not exist Opts: =any other=
"start cmd /c cykl %.W %format.cmd %N" =>
"start cmd /c cykl E:\TEXT\BROUK.TEX latex.cmd E:/TEXT/BROUK"
"start /fs dviscr %viewopts %M.dvi" =>
"start /fs dviscr /tr1 /m1440 e:\text\brouk.dvi"
*/
include 'stdconst.e'
/************************ CONSTANTS *********************************/
const
PM_STARTos2 = 'start /C /WIN '
PM_STARTos2fs = 'start /C /FS '
PM_STARTcmd = 'start /C /WIN cmd /c '
PM_STARTpm = 'start '
PM_STARTdos = 'start /C /WIN /DOS command.com /c '
PM_STARTdosfs = 'start /C /FS /DOS command.com /c '
/* Message strings */
pm_expand_inf = "Expand command with: Work file: %w (name) %.w (ext) %W (path\name) %.W (full name); Main drive:\dir %d; 'MASTER:' file: %m %.m %M %.M; 'FORMAT:' %format 'ORIENTATION:' %orient; 'ETC:' %etc; 'CHOICE:' %choice; Verbatims: 'EMTEXOPT:' %optsemtex; 'DVIPS:' %optsdvips; 'VIEWOPTS:' %viewopts; 'OPTS:' %opts"
pm_command_os2_inf = "Expand command line (as pm_expand) and execute OS/2 exe program"
pm_command_os2fs_inf = "Expand command line (as pm_expand) and execute full-screen OS/2 exe program"
pm_command_cmd_inf = "Expand command line (as pm_expand) and execute .cmd file"
pm_command_pm_inf = "Expand command line (as pm_expand) and execute Prezentation Manager program"
pm_command_dos_inf = "Expand command line (as pm_expand) and execute dos exe program"
pm_command_dosfs_inf = "Expand command line (as pm_expand) and execute dos exe program (full screen)"
/* The following command adds the action commands to the list */
DEFINIT
universal pm4epm_MasterNotFound
DEFC pm4epm_actionlist
universal ActionsList_FileID
insertline 'pm_expand'pm_expand_inf'pm4epm',ActionsList_FileID.last+1,ActionsList_FileID
insertline 'pm_command_cmd'pm_command_cmd_inf'pm4epm',ActionsList_FileID.last+1,ActionsList_FileID
insertline 'pm_command_os2'pm_command_os2_inf'pm4epm',ActionsList_FileID.last+1,ActionsList_FileID
insertline 'pm_command_os2fs'pm_command_os2fs_inf'pm4epm',ActionsList_FileID.last+1,ActionsList_FileID
insertline 'pm_command_pm'pm_command_pm_inf'pm4epm',ActionsList_FileID.last+1,ActionsList_FileID
insertline 'pm_command_dos'pm_command_dos_inf'pm4epm',ActionsList_FileID.last+1,ActionsList_FileID
insertline 'pm_command_dosfs'pm_command_dosfs_inf'pm4epm',ActionsList_FileID.last+1,ActionsList_FileID
/*************************** ROUTINES ******************************/
DEFPROC PM_GetNextWord ( WhichWord, line, uline )
-- routine returns the next word after the keyword WhichWord or WhichWord:
i = wordpos(WhichWord,uline)
if i=0 then i = wordpos(WhichWord':',uline) endif
if i=words(uline) then i=0; TheWord='' endif
if i<>0 then TheWord=word(line,i+1)
else TheWord=''
endif
return TheWord
DEFPROC PM_GetNextWordOptions ( WhichWord, line, uline )
-- routine scans for WhichWord. The first char of the next word as taken as the
-- key char. Then line is copied to TheOpts until the next key char appears.
-- This is similar to \verb*TheOpts...* in LaTeX
i = wordpos(WhichWord,uline)
if i=0 then i = wordpos(WhichWord':',uline) endif
if i=words(uline) then i=0; TheOpts='' endif
if i<>0
then TheOpts=subword(line,i+1,words(line)-i)
KeyChar=substr(TheOpts,1,1); TheOpts=delstr(TheOpts,1,1)
i=pos(KeyChar,TheOpts)
if (i<>0) then TheOpts=substr(TheOpts,1,i-1) endif
else TheOpts=''
endif
return TheOpts
DEFPROC PM_SubstKeys ( TheCommand, TheKey, ByWhat )
-- routine substitutes TheKey strings by ByWhat strings in TheCommand
i = pos(TheKey,TheCommand)
do while (i<>0)
l = length(TheKey)
TheCommand = substr(TheCommand,1,i-1)ByWhat''substr(TheCommand,i+l,length(TheCommand)-i-l+1)
i = pos(TheKey,TheCommand)
end
return TheCommand
DEFPROC PM_SubstEnvironment ( TheCommand )
-- routine substitutes the environmental variables (like $(PATH)) within TheCommand
i = pos('$(',TheCommand)
do while (i<>0)
e = substr(TheCommand,i+2,length(TheCommand)-i-2)
TheCommand = substr(TheCommand,1,i-1)
i = pos(')',e)
if i>0
then TheCommand=TheCommand''get_env(substr(e,1,i-1))''substr(e,i+1,length(e)-i-1)
else TheCommand=TheCommand''get_env(substr(e,1,length(e)))
endif
i = pos('$(',TheCommand)
end
return TheCommand
DEFPROC save_the_ring() =
n = filesinring()
for i = 1 to n
if .modify then call savefile(.filename); endif
nextfile
endfor
return
DEFPROC InfoBox( title, text) = --Information box
call WinMessageBox( title, text, MB_OK + MB_MOVEABLE + MB_INFORMATION )
return
/* ErrorBox */
DEFPROC ErrorBox( title, text) =
Beep(440, 133)
call WinMessageBox( title, text, MB_OK + MB_MOVEABLE + MB_ERROR )
return
/* Debug box */
DEFPROC DebugBox( text ) =
call WinMessageBox( 'Debugging', text, MB_OK + MB_MOVEABLE + MB_NOICON )
return
/* Split file name into parts. Taken from ZWepmTeX.e by Z. Wagner */
DEFPROC split_file_name(var drive, var path, var base, var ext, filespec) =
fn = strip(filespec)
if substr(fn, 2, 1) = ':' then
drive = substr(fn, 1, 2)
fn = substr(fn, 3)
else drive = ''
endif
dotpos = lastpos('.', fn)
bspos = lastpos('\', fn)
if dotpos <= bspos then dotpos = length(fn) + 1; endif
path = substr(fn, 1, bspos)
base = substr(fn, bspos+1, dotpos-bspos-1)
ext = substr(fn, dotpos)
return
/**************************** DEFINE pm_command **********************/
DEFPROC pm_expansion ( TheCommand )
universal pm4epm_MasterNotFound;
/* Read the first line of the current file in order to find Main file */
EF = .filename; MF = '';
TheFormat=''; TheEtc=''; TheOrient=''; TheChoice='';
TheOpts=''; TheViewOpts=''; TheDvips=''; TheEmtexOpt=''
pm4epm_MasterNotFound=0 -- clear toggle
/*** Analysis of the first line of the current file ***/
/* search Master or Master: ; result goes to MF */
getline line, 1
uline = translate(line) -- uppercase
-- parse value uline with . 'MASTER' ':' MF . -- this would not be case sensitive
MF=PM_GetNextWord('MASTER',line,uline)
if MF='' then MF=.filename; MFisEF=1
else MFisEF=0; MF = translate(MF,'\','/') -- convert from unix format
endif
-- the following deals with the case when user specifies only file name
-- It work with absolute path, but not with relative paths having ..\
if pos('\',MF)=0 then
if already_in_ring(MF,n) then -- suggestion by kroni@bite.shnet.org, 16.5.1996
MF=n.filename
else
i=pos(':',MF); if i>0 then MF=substr(MF,i+1,length(MF)-i); endif -- no drive letter if specified MF=directory()'\'MF;
MF=directory()'\'MF
endif
endif
if not exist(MF) then
-- beep(444,222); sayerror 'Master file 'MF' not found!'
ErrorBox('Error','Master file 'MF' not found!')
pm4epm_MasterNotFound=1;
-- return
endif
/* fill MF-compliant variables */
-- oh... REXX has MFdrive = filespec("Drive",MF), but E not !
call split_file_name(MFdrive, MFdir, MFname, MFext, MF)
call split_file_name(EFdrive, EFdir, EFname, EFext, EF)
if (MFisEF==0) then -- files are different
if (MFdrive='') then MFdrive=EFdrive endif
if (MFdir='') then MFdir=EFdir endif
endif
MFdir = delstr(MFdir, length(MFdir)) -- del last backslash
MainDirectory = MFdrive''MFDir
MFext = delstr(MFext, 1,1) -- del .
MFwholename = MainDirectory'\'MFname
EFext = delstr(EFext,1,1) -- del .
if (MFisEF=1)
then EFdrive=MFdrive; EFdir=MFdir
else EFdir = delstr(EFdir, length(EFdir)) -- del last backslash
endif
EFwholename = EFdrive''EFdir'\'EFname
/* Now master file MF and edit file EF are fully qualified.
We should read the first line of the master file to get the information
about Format, Orientation, Etc, Opts
*/
if (MFisEF=0) then -- read line, uline from Master
if pfile_exists(MF)
then /* if Master file is in the ring */
getfileid working_fid
getfileid master_fid,MF
activatefile master_fid
getline line, 1
activatefile working_fid
else
'edit /d' MF
getfileid master_fid
getline line, 1
'quit'
endif
uline = translate(line)
endif
/* Now parse line (note: uline is line in uppercase) */
TheFormat=PM_GetNextWord('FORMAT',line,uline)
if TheFormat='' then TheFormat=get_env('TEXFORMATDEFAULT') endif
if TheFormat='' then TheFormat='latex' endif
TheOrient=PM_GetNextWord('ORIENTATION',line,uline)
TheEtc=PM_GetNextWord('ETC',line,uline)
TheChoice=PM_GetNextWord('CHOICE',line,uline)
-- TheOpts=PM_GetNextWord('OPTS',line,uline)
TheOpts = PM_GetNextWordOptions('OPTS',line,uline)
TheViewOpts = PM_GetNextWordOptions('VIEWOPTS',line,uline)
TheDvips = PM_GetNextWordOptions('DVIPS',line,uline)
TheEmtexOpt = PM_GetNextWordOptions('EMTEXOPT',line,uline)
/* Finally perform the substitution on TheCommand
Not for those who want to expand this list: long commands (%opt) must precede
the short ones (%o) !
*/
/* strings cannot be empty nor spaces since they will be chained */
if EFname='' then EFname=\250 endif
if EFext='' then EFext=\250 endif
if MFname='' then MFname=\250 endif
if MFext='' then MFext=\250 endif
if MainDirectory='' then MainDirectory=\250 endif
if TheFormat='' then TheFormat=\250 endif
if TheOrient='' then TheOrient=\250 endif
if TheEtc='' then TheEtc=\250 endif
if TheChoice='' then TheChoice=\250 endif
XMF = translate(MF,'/','\') -- convert to unix format
XMFwholename = translate(MFwholename,'/','\')
XEF = translate(EF,'/','\')
XEFwholename = translate(EFwholename,'/','\')
XMainDirectory = translate(MainDirectory,'/','\')
Shorts = '%% ' -- hide %% sequence
Longs = '!$PETR$! '
Shorts = Shorts'%w %W %.w %.W '
Longs = Longs''EFname' 'EFwholename' 'EFext' 'EF ' '
Shorts = Shorts'%m %M %.m %.M '
Longs = Longs''MFname' 'MFwholename' 'MFext' 'MF' '
Shorts = Shorts'%x %X %.x %.X '
Longs = Longs''EFname' 'XEFwholename' 'EFext' 'XEF ' '
Shorts = Shorts'%n %N %.n %.N '
Longs = Longs''MFname' 'XMFwholename' 'MFext' 'XMF' '
Shorts = Shorts'%h %d %D '
Longs = Longs''MFdrive' 'MainDirectory' 'XMainDirectory' '
Shorts = Shorts'%choice %format %etc %orient '
Longs = Longs''TheChoice' 'TheFormat' 'TheEtc' 'TheOrient' '
TheCommand=translate(TheCommand,'',\250) -- del those 250
/* replace single words */
do i = 1 to words(Shorts)
sh = word(Shorts, i)
p = pos(sh,TheCommand)
do while (p<>0)
l = length(sh)
TheCommand = substr(TheCommand,1,p-1)word(Longs,i)substr(TheCommand,p+l,length(TheCommand)-p-l+1)
p = pos(sh,TheCommand)
end
end
/* replace single words by long words (verbatims) */
TheCommand=PM_SubstKeys(TheCommand,'%optsemtex',TheEmtexOpt)
TheCommand=PM_SubstKeys(TheCommand,'%optsdvips',TheDvips)
TheCommand=PM_SubstKeys(TheCommand,'%opts',TheOpts)
TheCommand=PM_SubstKeys(TheCommand,'%viewopts',TheViewOpts)
TheCommand=PM_SubstKeys(TheCommand,'!$PETR$!','%%') -- restore %%
TheCommand=PM_SubstEnvironment(TheCommand)
/*
sayerror "RESULT="TheCommand
WinMessageBox( 'PM for himself', 'Continue...', MB_OK + MB_MOVEABLE + MB_ERROR)
better: DebugBox('RESULT='TheCommand)
*/
RETURN TheCommand
/**************************** DEFINE pm_command_cmd **********************/
DEFPROC pm_command_start ( action, HowStart, TheCommand, TheInfo )
if action = 'S' then
/* button launched => replace %xxx sequences and run TheCommand */
if TheCommand='' then
ErrorBox('Please define your action in the icon/edit/customization/parameters')
return
endif
TheCommand=pm_expansion(TheCommand)
-- how to detect if all is OK?
save_the_ring()
HowStart''TheCommand
return
/* this is obsolete now
if (word(TheCommand,1)='-')
then TheCommand=subword(TheCommand,2,words(TheCommand)-1)
sayerror 'STARTing 'TheCommand
'START 'TheCommand
elseif (word(TheCommand,1)='--') then
TheCommand=subword(TheCommand,2,words(TheCommand)-1)
sayerror 'STARTing 'TheCommand
TheCommand
else sayerror PMOS2cmd '"'TheCommand'"'
PMOS2cmd '"'TheCommand'"'
endif
*/
/**** HELP ACTION ****/
elseif action ='H' then sayerror 'Here can be help window or sth like that'
/**** INFO ACTION (button held on the icon) ****/
elseif action ='I' then sayerror TheInfo
else ErrorBox("Error", 'The action 'action' is not implemented')
endif
return
/**************** END OF pm_command_start *************************/
DEFC pm_expand
parse arg action TheCommand
pm_command_start(action,'',TheCommand,pm_expand_inf)
DEFC pm_command_os2
parse arg action TheCommand
pm_command_start(action,PM_STARTos2,TheCommand,pm_command_os2_inf)
DEFC pm_command_os2fs
parse arg action TheCommand
pm_command_start(action,PM_STARTos2fs,TheCommand,pm_command_os2fs_inf)
DEFC pm_command_cmd
parse arg action TheCommand
-- InfoBox('DEFC','action='action' TheCommand='TheCommand)
pm_command_start(action,PM_STARTcmd,TheCommand,pm_command_cmd_inf)
DEFC pm_command_pm
parse arg action TheCommand
pm_command_start(action,PM_STARTpm,TheCommand,pm_command_pm_inf)
DEFC pm_command_dos
parse arg action TheCommand
pm_command_start(action,PM_STARTdos,TheCommand,pm_command_dos_inf)
DEFC pm_command_dosfs
parse arg action TheCommand
pm_command_start(action,PM_STARTdosfs,TheCommand,pm_command_dosfs_inf)
/* end of pm4EPM */